package day1027.dem4.one;

import java.lang.reflect.Method;

/**
 * @program: fanxing
 * @description:
 * @author: 诸葛龙辰
 * @create: 2022-10-27 16:53
 **/
public class Test {
    public static void main(String[] args) throws Exception {
        Class<?> aClass = Class.forName("day1027.dem4.one.Cat");
/**
 *1 . Method getDeclaredMethod(String name, 类<?>... parameterTypes)
 *   根据方法名和参数获取本类中指定的方法对象
 */


        Method fun1 = aClass.getDeclaredMethod("fun1");

        //普通: 对象名.方法(实参)  反射: 方法对象。invoke(对象名,实参)
        Object o = aClass.newInstance();
        Object result = fun1.invoke(o);
        //方法的回调
        System.out.println(result);

        Method fun2 = aClass.getDeclaredMethod("fun2", String.class, Integer.class);
        Object r = fun2.invoke(o, "佩奇", 3);
        System.out.println(r);

    }
}

class Animal{
    public void show(){
        System.out.println("动物的show方法");
    }
    private void print(){
        System.out.println("动物的print方法");
    }
}
class Cat extends  Animal{
    public void fun1(){
        System.out.println("Cat中的fun1方法");
    }
    public String fun2(String name,Integer age){
        System.out.println("cat中fun2方法"+name);
        return "啦啦啦";
    }

}
